package com.digua.base.base

import android.app.Presentation
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Display
import android.view.LayoutInflater
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import androidx.viewbinding.ViewBinding
import com.digua.base.listener.RegisterForActivityResultListener
import com.digua.base.util.LogUtil
import java.lang.reflect.ParameterizedType

open class Presentation<UI : ViewBinding> : Presentation{
    lateinit var ui: UI
    var ctx: Context

    @JvmOverloads
    constructor(context: Context, display: Display, theme: Int = 0) : super(context, display, theme) {
        ctx = context
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        try {
            if (javaClass.genericSuperclass is ParameterizedType) {
                val type = javaClass.genericSuperclass as ParameterizedType
                val cls = type.actualTypeArguments[0] as Class<*>
                val inflate = cls.getDeclaredMethod("inflate", LayoutInflater::class.java)
                ui = inflate.invoke(null, layoutInflater) as UI
                setContentView(ui.root)
            }
        } catch (e: java.lang.Exception) {
            LogUtil.e("异常:", e)
        }
    }

}